package model
{
	import actions.WBAction;
	
	import avmplus.getQualifiedClassName;
	
	import events.ObjectEvent;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.utils.UIDUtil;
	
	import undoredo.IUndoRedo;
	
	
	public class WBObject extends EventDispatcher implements IUndoRedo
	{
		private var _uid:String;
		private var _selected:Boolean = false;
		private var _state:String = "default";
		private var _width:Number = 0;
		private var _height:Number = 0;
		private var _dragging:Boolean = false;
		protected var _objectType:String = "";
		private var _xPos:Number;
		private var _yPos:Number;
		private var _className:String;
		
		public function WBObject(target:IEventDispatcher=null)
		{
			super(target);
			_uid = UIDUtil.createUID();
			_className = getQualifiedClassName(this);
		}
		
		public function get className():String
		{
			return _className;
		}

		public function set className(value:String):void
		{
			_className = value;
		}

		[Bindable]
		public function get yPos():Number
		{
			return _yPos;
		}

		public function set yPos(value:Number):void
		{
			_yPos = value;
		}
		
		[Bindable]
		public function get xPos():Number
		{
			return _xPos;
		}

		public function set xPos(value:Number):void
		{
			_xPos = value;
		}

		public function moveObjectBy(deltaX:Number, deltaY:Number):void
		{
			xPos += deltaX;
			yPos += deltaY;
			dispatchEvent(new ObjectEvent(ObjectEvent.OBJECT_MOVED));
		}
		
		public function get objectType():String
		{
			return _objectType;
		}
		
		public function get uid():String
		{
			return _uid;
		}

		public function set uid(value:String):void
		{
			_uid = value;
		}

		public function get dragging():Boolean
		{
			return _dragging;
		}
		[Bindable]
		public function set dragging(value:Boolean):void
		{
			_dragging = value;
		}

		[Bindable]
		public function set selected(value:Boolean):void
		{
			_selected = value;
			if(_selected)
			{
				state = "selected";
				var e:ObjectEvent = new ObjectEvent(ObjectEvent.OBJECT_SELECTED);
				dispatchEvent(e);
			}
			else
			{
				state = "default";
			}
			
		}
		
		public function get selected():Boolean
		{
			return _selected;
		}
		

		[Bindable]
		public function set width(value:Number):void
		{
			_width = value;
		}
		
		public function get width():Number
		{
			return _width;
		}
		
		[Bindable]
		public function set height(value:Number):void
		{
			_height = value;
		}
		
		public function get height():Number
		{
			return _height;
		}
		
		[Bindable]
		public function set state(value:String):void
		{
			_state = value;
		}
		
		public function get state():String
		{
			return _state;
		}
		
		public function redo(action:WBAction):void
		{
			//TODO
		}
		public function undo(action:WBAction):void
		{
			//TODO
		}
		
		/**
		 * This method informs the controller for a change in the model
		 */
		public function invalidateProperties():void
		{
			
		}
	
	}
}